﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <!-- 增加一个配置  -->
    <script src="../../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../../Comm/Gener.js" type="text/javascript"></script>

    <link href="../../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../js/ueditor/dialogs/internal.js"></script>
    <style type="text/css">
        .trSP {
            background-color: #B9D3EE
        }

        .table-head {
            padding-right: 17px;
            background-color: #999;
            color: #000;
        }

        .table-body {
            width: 100%;
            height: 390px;
            overflow-y: scroll;
        }

            .table-head table, .table-body table {
                width: 100%;
            }

            .table-head tr, .table-body tr {
                line-height: 35px;
            }

            .table-head th, .table-body td {
                text-align: center;
            }

            .table-body table tr:nth-child(2n+1) {
                background-color: #f2f2f2;
            }

        .total {
            float: right;
            padding-right: 20px;
            margin-top: 5px;
        }
    </style>

    <script language="javascript" type="text/javascript">
        var dataType = GetQueryString("DataType");
        var fk_mapData = GetQueryString("FK_MapData");
        $(function () {

            var enumMains = new Entities("BP.Sys.SysEnumMains");
            enumMains.RetrieveAll();

            var html = "<table border=0;algin='left'; style='width:100%;'>";
            html += "<tr>";
            html += "<th>Idx</th>";
            html += "<th>编号</th>";
            html += "<th>名称</th>";
            html += "<th>配置值</th>";
            html += "<th>操作</th>";
            html += "</tr>";

            for (var i = 0; i < enumMains.length; i++) {

                var sysEnumMain = enumMains[i];
                var cfgVal = sysEnumMain.CfgVal.replace(/ /g, "[]");

                html += "<tr>";
                html += "<td style='width:3%' class=Idx>" + i + "</td>";
                html += "<td style='width:10%'><label onclick=getTr('" + sysEnumMain.No + "','" + sysEnumMain.Name + "','" + cfgVal + "'," + i + ") ><input type=Radio name='aa' />" + sysEnumMain.No + "</label></td>";
                html += "<td style='width:20%'>" + sysEnumMain.Name + "</td>";
                html += "<td style='width:50%;text-overflow: ellipsis;overflow: hidden;' ><a href=\"javascript:Edit('" + sysEnumMain.No + "');\">" + sysEnumMain.CfgVal + "</a></td>";

                html += "<td style='width:10%'><img src='../../../Img/Btn/Delete.gif' onclick=\"Del('" + sysEnumMain.No + "')\" /></td>";

                html += "</tr>";
            }

            html += "</table>";

            $("#table").html(html);

        });

        var rownum = -1;
        function getTr(No, Name, CfgVal, i) {
            CfgVal = CfgVal.replace(/[]/g, " ");
            $('#TB_Name').val(Name);
            $('#TB_KeyOfEn').val(No);
            $('#TB_UIBindKey').val(No);
            $('#TB_Vals').val(CfgVal);
        }

        //传入父窗体
        function GetFrmInfo() {
            return {
                Name: $.trim($("#TB_Name").val()),
                KeyOfEn: $.trim($("#TB_KeyOfEn").val()),
                IsCreateLabel: $("#CB_Generate_Tags").prop("checked"),
                UIBindKey: $.trim($("#TB_UIBindKey").val()),
                Vals: $.trim($("#TB_Vals").val())
            };
        }

        function NewEnum() {
            var url = "EnumerationNew.htm";

            OpenDialogAndCloseRefresh(url, '新建枚举', 560, 400, null, function () { window.location.href = window.location.href; });
        }


        function Del(key) {

            var v = window.confirm("您确定要删除枚举值[" + key + "]吗？");
            if (v == false)
                return;

            //检查该枚举值是否被其他表单字段引用.
            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("UIBindKey", key);

            var info = '';
            for (var i = 0; i < mapAttrs.length; i++) {
                var attr = mapAttrs[i];
                info += "\t\n" + i + ",表单编号:" + attr.FK_MapData + " , 字段:" + attr.KeyOfEn + ", 名称:" + attr.Name;
            }

            if (info != '') {

                info = "如下表单引用了该字段您不能删除:" + info;
                alert(info);
                return;
            }

            //执行删除.
            var enumMain = new Entity("BP.Sys.SysEnumMain", key);
            enumMain.Delete();

            window.location.href = window.location.href;
        }
        function Edit(key) {
            var url = "EnumerationNew.htm?DoType=FrmEnumeration_SaveEnum&EnumKey=" + key;
            OpenDialogAndCloseRefresh(url, '编辑枚举', 560, 400, null, function () { window.location.href = window.location.href; });
        }

        var thePlugins = 'enum';
        dialog.oncancel = function () {
            if (UE.plugins[thePlugins].editdom) {
                delete UE.plugins[thePlugins].editdom;
            }
        };
        dialog.onok = function () {
            var name = $.trim($("#TB_Name").val());
            var KeyOfEn = $.trim($("#TB_KeyOfEn").val());
            var UIBindKey = $.trim($("#TB_UIBindKey").val());
            var vals = $.trim($('#TB_Vals').val());
            if (name == null || name.length == 0) {
                $.messager.alert('错误', '字段名称不能为空。', 'error');
                return false;
            }
            if (KeyOfEn == null || KeyOfEn.length == 0) {
                $.messager.alert('错误', '英文字段不能为空。', 'error');
                return false;
            }

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner");
            handler.AddPara("KeyOfEn", KeyOfEn);
            handler.AddPara("FK_MapData", fk_mapData);
            handler.AddPara("EnumKey", UIBindKey);
            if (dataType == "Radio")
                handler.AddPara("UIContralType", 3);
            else if (dataType == "Select")
                handler.AddPara("UIContralType", 1);
            else if (dataType == "CheckBox")
                handler.AddPara("UIContralType", 2);
            var data = handler.DoMethodReturnString("SysEnumList_SaveEnumField");
            if (data.indexOf("err@") >= 0) {
                alert(data);
                return;
            }
            var _Html = "";
            var strs = [];
            if (vals != null && vals != "") {
                strs = vals.split("@")
            }
            //单选按钮
            if (dataType == "Radio") {
                if (strs.length != 0) {
                    _Html += "<span leipiplugins='enum' id='SR_" + KeyOfEn + "' title='单选' name='leipiNewField'  data-key='" + KeyOfEn + "' data-type='" + dataType + "'  data-bindKey='" + UIBindKey + "'>";
                    for (var i = 0; i < strs.length; i++) {
                        var keyVal = strs[i].split("=")
                        if (keyVal.length == 2)
                            _Html += "<label><input type='radio' value= '" + keyVal[0] + "' id='RB_" + KeyOfEn + "_" + keyVal[0] + "' name='RB_" + KeyOfEn + "' data-key='" + KeyOfEn + "'  data-type='" + dataType + "'   data-bindKey='" + UIBindKey + "' class='form-control'  style='width:15px;height:15px;'/>" + keyVal[1] + "&nbsp;&nbsp;</label>";
                    }
                    _Html += "</span>";

                }
            }
            if (dataType == "Select") {
                if (strs.length != 0) {
                    _Html += "<span leipiplugins='enum' id='SS_" + KeyOfEn + "' title='下拉框' name='leipiNewField' data-type='EnumSelect'   data-bindKey='" + UIBindKey + "'>";
                    _Html += "<select id='DDL_" + KeyOfEn + "' name='DDL_" + KeyOfEn + "' data-type='EnumSelect' data-key='" + KeyOfEn + "' class='form-control' >";
                    for (var i = 0; i < strs.length; i++) {
                        var keyVal = strs[i].split("=")
                        if (keyVal.length == 2)
                            _Html += "<option value='" + keyVal[0] + "'>" + keyVal[1] + "</option>";
                    }
                    _Html += "</select>";
                    _Html += "</span>";
                    _Html += name;
                }
            }
            if (dataType == "CheckBox") {
                if (strs.length != 0) {
                    _Html += "<span leipiplugins='enum' id='SC_" + KeyOfEn + "' title='复选框' name='leipiNewField' data-type='EnumCheckBox'   data-bindKey='" + UIBindKey + "'>";
                    for (var i = 0; i < strs.length; i++) {
                        var keyVal = strs[i].split("=")
                        if (keyVal.length == 2)
                            _Html += "<label><input type='checkbox' value= '" + keyVal[0] + "' id='CB_" + KeyOfEn + "_" + keyVal[0] + "' name='CB_" + KeyOfEn + "' data-key='" + KeyOfEn + "'  data-type='" + dataType + "'   data-bindKey='" + UIBindKey + "' class='form-control'  style='width:15px;height:15px;'/>" + keyVal[1] + "&nbsp;&nbsp;</label>";
                    }
                    _Html += "</span>";
                }
            }
            editor.execCommand('insertHtml', _Html);
        };
        //查询枚举
        function SelectEnum() {
            var EnumName = document.getElementById("EnumValue").value;
            if (EnumName == "")
                var sql = "SELECT * FROM Sys_EnumMain";
            else
                var sql = "SELECT * FROM Sys_EnumMain WHERE (No like '%" + EnumName + "%') OR (Name like '%" + EnumName + "%')";
            var sysEnumMains = DBAccess.RunSQLReturnTable(sql);
            var newRow = "<table border=0;algin='left'; style='width:100%;'>";
            newRow += "<tr>";
            newRow += "<th>Idx</th>";
            newRow += "<th>编号</th>";
            newRow += "<th>名称</th>";
            newRow += "<th>配置值</th>";
            newRow += "<th>操作</th>";
            newRow += "</tr>";
            newRow += "<tr>";

            for (var i = 0; i < sysEnumMains.length; i++) {
                sysEnumMain = sysEnumMains[i];
                var cfgVal = sysEnumMain.CfgVal.replace(/ /g, "[]");
                newRow += "<td style='width:3%' class=Idx>" + i + "</td>";
                if (fk_mapData != null)
                    newRow += "<td style='width:10%'><label onclick=getTr('" + sysEnumMain.No + "','" + sysEnumMain.Name + "','" + cfgVal + "'," + i + ") ><input type=Radio name='aa' />" + sysEnumMain.No + "</label></td>";
                else
                    newRow += "<td style='width:10%'>" + sysEnumMain.No + "</td>";
                newRow += "<td style='width:20%'>" + sysEnumMain.Name + "</td>";
                newRow += "<td style='width:50%'><a href=\"javascript:Edit('" + sysEnumMain.No + "','" + sysEnumMain.Name + "','" + sysEnumMain.CfgVal + "')\" >" + sysEnumMain.CfgVal + "</a></td>";
                newRow += "<td style='width:10%'><img src='../../../Img/Btn/Delete.gif' onclick=\"Del('" + sysEnumMain.No + "')\" /></td>";

                newRow += "</tr>";
            }
            newRow += "</table>";
            if (newRow != undefined)
                $("#table").html(newRow);
            else
                alert("关键字查询无结果");
        }
    </script>
</head>
<body>
    <div class="table-head">
        <table style="width:100%;">
            <tr>
                <td>中文名 </td>
                <td><input id="TB_Name" class="easyui-textbox" style="width: 150px" /> </td>
                <td>字段英文名 </td>
                <td><input id="TB_KeyOfEn" class="easyui-textbox" style="width: 150px" /> </td>
                <td><input id="CB_Generate_Tags" type="checkbox" checked="checked" /><label for="CB_Generate_Tags">生成标签</label> </td>
                <td> <input type="button" id="Btn_New" class="easyui-button" onclick="NewEnum()" value="新建" /> </td>

                <td>关键字 </td>
                <td><input id="EnumValue" class="easyui-textbox" style="width:100px" /> </td>
                <td><input type="button" id="Btn_New" class="easyui-button" onclick="SelectEnum()" value="查询" /> </td>

            </tr>
        </table>
    </div>
    <div class="table-body">
        <div style="position:relative">
            <div id="table"></div>
        </div>
    </div>
    <input id="TB_UIBindKey" class="easyui-textbox" style="width: 200px; visibility:hidden" />
    <input id="TB_Vals" class="easyui-textbox" style="width: 200px; visibility:hidden" />

</body>
</html>
